package com.example.workbench.common.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
//import org.springframework.stereotype.Component;

import java.time.LocalDateTime;


@Component
public class MyMetaObjectHandler implements MetaObjectHandler {


    private static final Logger LOGGER = LoggerFactory.getLogger(MyMetaObjectHandler.class);

    public MyMetaObjectHandler() {
    }

    @Override
    public void insertFill(MetaObject metaObject) {
        LOGGER.debug("start insert fill ....");
        System.out.println("------------------------time-------------------------");
        this.setFieldValByName("createTime", LocalDateTime.now(), metaObject);
        this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        LOGGER.debug("start update fill ....");
        System.out.println("------------------------time-------------------------");
        System.out.println(LocalDateTime.now());
        this.setFieldValByName("updateDate", LocalDateTime.now(), metaObject);
    }
}
